package com.lz.servlet.controller;

import com.google.gson.Gson;
import com.lz.common.utils.SpringUtil;
import com.lz.common.utils.weather.WeatherService;
import com.lz.service.excel.config.ExcelDemo;
import com.lz.service.security.config.User;
import com.lz.service.security.config.mapper.UserMapper;
import com.lz.servlet.domain.dto.DemoDTO;
import com.lz.servlet.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.HandlerMapping;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.List;


@RequestMapping("/test")
@RestController
@Slf4j
@RequiredArgsConstructor
public class TestController {

    @Autowired
    private UserService userService;

    public void setUserService(UserService userService) {
        System.out.println(userService+"111111111111111111111111111111111111111");
    }


    @Resource
    private UserMapper userMapper;



    @Resource
    private Gson gson;
    @Autowired
    private List<HandlerMapping> handlerMappings;


    @RequestMapping("/hello")
    public void hello() throws IOException {
        System.out.println(this.hashCode());
        log.info("进入方法");
        List<User> users = userMapper.selectList(null);
        File file = ExcelDemo.generateExcelFile(users);
        ExcelDemo.writeExcelToResponse(file);
    }

    @GetMapping("/getWeather")
    public String getWeather(String cityName) {
        for (HandlerMapping mapping : handlerMappings) {
            log.info("Registered HandlerMapping: {}", mapping);
        }
        HandlerMapping bean = SpringUtil.getBean(HandlerMapping.class);
        Object bean1 = SpringUtil.getBean("requestMappingHandlerMapping");
        System.out.println("你看看把" + bean1);
        System.out.println("你看看把" + bean);
        String weather = WeatherService.getWeather(cityName);
        System.out.println(weather);
        return weather;
    }

    @GetMapping("/getLocalWeather")
    public String getLocalWeather() {
        return WeatherService.getLocalWeather();
    }

    @GetMapping("/demo01")
    public String demo01(@RequestBody DemoDTO f) {
        System.out.println(f);
        return null;
    }

}
